import mockjs from 'mockjs';
const stuDataList = mockjs.mock({
  'data|10': [
    {
      id: '@id()',
      name: '@cname',
      score: '@integer(30, 100)',
      created_at: '@date',
      province: '@province',
      city: '@city',
    },
  ],
});
export default {
  // 获取数据
  'GET /api/stu': (req, res) => {
    res.send({
      code: '200',
      msg: '学员列表加载成功',
      data: stuDataList.data,
    });
  },
  // 删除数据
  'DELETE /api/stu': (req, res) => {
    // 获取参数
    const { id } = req.query;
    stuDataList.data = stuDataList.data.filter((v) => v.id !== id);
    res.send({
      code: '200',
      msg: '学员删除成功',
    });
  },
  // 编辑数据
  'PUT /api/stu': (req, res) => {
    // 获取参数
    const index = stuDataList.data.findIndex((v) => v.id === req.body.id);
    stuDataList[index] = req.body;
    // stuDataList.data.find(v => v.id === req.body.id) = req.body
    res.send({
      code: '200',
      msg: '学员编辑成功',
    });
  },
};
